An attorney for North Carolina on Wednesday defended a state law that lets magistrates refuse to perform same-sex marriages, telling a federal appeals court that the policy accommodates officials’ religious beliefs while complying with the law on gay marriage.

A special deputy attorney general for North Carolina told a three-judge panel of the 4th U.S. Circuit Court of Appeals that lawmakers worked hard to strike a fair balance with the law by ensuring that willing magistrates from nearby communities come in to perform marriages when others refuse.

“The state is doing exactly what it is supposed to do,” said Olga Vysotskaya de Brito.

At issue before the court is whether couples seeking to challenge the law have legal standing to do so.

The couples say they have the right to sue because North Carolina is spending public funds to pay for magistrates to travel to perform same-sex marriages if counterparts in another area all recuse themselves.

But while two judges said they’re sympathetic to concerns with the law, they also questioned whether the court can allow the couples’ case to proceed.

“I hope you understand that there’s a difference between what judges may or may not favor as a matter of policy and what we may do under the law,” Judge J. Harvie Wilkinson III told Luke Largess, an attorney for the couples.

The 2015 law, known as SB2, allows magistrates to recuse themselves from performing marriages “based on any sincerely held religious objections.” Those who file such notices are prevented from officiating at all marriages — gay and heterosexual — for at least six months. The law also allows some court clerks to decline to issue marriage licenses.

The couples — two gay and one interracial — want the 4th Circuit to overturn a lower court ruling dismissing the case.

Their argument hinges on the law’s authorization of magistrates to travel between jurisdictions to perform marriages if counterparts in another area all recuse themselves. The law also allows for restoration of some retirement benefits if a magistrate resigns after gay marriage became legal but was reappointed around when the recusal law took effect.

Two of the North Carolina plaintiffs are from McDowell County, where all magistrates recused themselves after the state law was passed, requiring North Carolina to pay a magistrate to come several days a week from nearby Rutherford County. Only a fraction of magistrates statewide have recused themselves.

Largess, the attorney for the couples, told the judges that the district court wrongly found the spending of taxpayer dollars to be “incidental.” Largess said North Carolina should be blocked from spending public funds to further a religious purpose.

Then, “the magistrates in the state would have to decide whether they’re going to uphold the oath of office or not,” Largess said.

As of late 2016, two other states — Utah and Mississippi — had laws allowing public officials to recuse themselves from performing marriages because of religious beliefs, according to the National Conference of State Legislatures.

The case comes as President Donald Trump wades into the question of protections for religious beliefs. He signed an executive order last week aimed at easing an IRS rule that limited political activity. Supporters had hoped for more sweeping protections for ministries, schools and federal workers.

Judge Barbara Milano Keenan said while she sympathizes with the couples’ objections to the law, taxpayer dollars in this case are not going directly to a religious entity, but to the judicial branch.

But she also expressed concern that the law could ultimately result in the state spending lots of public funds.

If magistrates say their religion doesn’t believe in interracial marriage, then North Carolina will be shuttling magistrates all over the state to perform such marriages, she said.

“There’s just so many different beliefs that are grounded in discrimination,” Keenan said.

The court is expected to issue a ruling in the coming weeks.

© 2017, Associated Press, All Rights Reserved.

This material may not be published, broadcast, rewritten, or redistributed.