You might imagine it’s a logistical nightmare filming a series like “Counterpart,” in which JK Simmons frequently acts opposite himself in the same scene — in the very same frame.

But Justin Marks, who created the Starz sci-fi/spy drama (already renewed for a second season), says Simmons has a secret weapon at his disposal: actor John Funk, his stand-in and friend.

“It was a lot of trial and error over the course of the season figuring it out, but we came up with a method,” says Marks. “JK was actually performing against another actor.”

In the series, Simmons plays Howard Silk, a low-level employee of a Berlin-based spy agency who discovers that he, and everyone else, has an identical double in a mirror-image world accidentally created by scientists years before (it’s known only to a select few and accessible through an underground portal). Howard eventually meets his double, Howard Prime, a no-nonsense assassin/spy shuttling back and forth between the two worlds, trying to avert a diplomatic disaster.

While Simmons is seen on-screen in both roles, he had an enormous assist from Funk, who sat across from Simmons in scenes in which the two Howards interact with each other — even dressing like either version of Howard to help Simmons react.

“It was important that the interaction between the two Howards feel like … live theater, where two actors are on stage together acting off each other,” says Marks. “We had to find a way, beyond the technical side of it, to provide JK with an environment where he could actually act against himself — and not just feel like he’s playing to the proverbial tennis ball [to look at while delivering his lines].

“John, who played Howard or Howard Prime in a given scene, was actually switching out with JK and changing costumes. He had to remember all the specific gestures JK made so that he was not just providing JK with an eyeline, but with an emotional compass to react against. It’s a thankless role … but it made our process come alive.

“When you see the two Howards interact, it feels seamless.”

‘It was important that the interaction between the two Howards feel like … live theater, where two actors are on stage together acting off each other’

Marks says the “Counterpart” crew also used old-fashioned split-screen techniques and computer-driven “motion control” photography to shoot some scenes featuring both Howards (including a scene in the premiere in which both Howards study some pastries). “Even though there’s something to the process that’s always going to be technical, we wanted to give JK as much space as possible to experiment as an actor,” Marks says, “and make it feel improvised and live.”

The series, co-starring Olivia Williams, Harry Lloyd, Ulrich Thomsen, Nazanin Boniadi and Sara Serraiocco, is set in Berlin but is shot in LA, using locales including the Orpheum Theatre and a bar in the city’s Silver Lake neighborhood. “I always wanted to do a show that felt like a throwback to the kind of Cold War espionage thrillers I grew up reading … [‘Counterpart’] is a conceit of a Berlin Wall thriller but the wall is a metaphysical construct,” Marks says. “We shot most of our stage work in LA to be close to JK’s home and we do location work at night in LA for a lot of scenes. Surprisingly, LA and Berlin do look a lot a like, especially at night in downtown LA.

“It’s a show you have to pay attention to, but we really worked hard as well to try to tell a story you can follow in human terms.”

“Counterpart” 8 p.m. Sunday on Starz