RALEIGH — A federal judge has dismissed a challenge to a North Carolina law that says magistrates with religious objections can refuse to marry same-sex couples.

The judge ruled the three couples who brought the case — two gay and one interracial — lacked legal standing to sue and lacked evidence showing they were harmed directly by the law that took effect in June 2015.

North Carolina and Utah are the only states currently enforcing such religious-recusal laws. About 5 percent of North Carolina’s magistrates have filed recusal notices, which prevent them 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 because of “any sincerely held religious objection.”

The plaintiffs argued they could sue because some taxpayer money was being used for travel expenses for other magistrates to come to McDowell County, where all the magistrates had recused themselves. But U.S. District Judge Max Cogburn wrote they didn’t point to any specific funds appropriated by the legislature to implement the law’s alleged unconstitutional purpose.

The couples who sued the state courts director also “lack standing by virtue of the fact that their claims are merely generalized grievances with a state law with which they disagree,” Cogburn said in the decision released late Tuesday.

The couples’ lawyers filed a notice Wednesday saying they’ll appeal Tuesday’s ruling to the 4th U.S. Circuit Court of Appeals. A married lesbian couple who sued and live in McDowell County told reporters last month they’re worried whether they can get equal and fair treatment from local magistrates, knowing their recusals.

The law “expressly declares that magistrates’ religious beliefs are superior to their oath of judicial office to uphold and support the federal constitution. And the law spends public money to advance those religious beliefs. That is a straightforward violation of the 1st Amendment,” Luke Largess, a lawyer for the couples, said in a news release.

Cogburn wrote that it’s possible someone could suffer real harm because of the law, but he said the plaintiffs provided no evidence that has actually happened. The law says a chief District Court judge or county Register of Deeds — both elected officials — must ensure marriage transactions are carried out if no one else is available.

Senate Leader Phil Berger, R-Rockingham, the chief sponsor of the legislation, said the law actually protects First Amendment rights.

“We appreciate the court recognizing the plaintiffs failed to identify even one North Carolinian who was denied the ability to get married under this reasonable law,” Berger said in a release.

During oral arguments last month over the state’s motion to dismiss the lawsuit, Cogburn pointed out that recusals can remain secret — particularly in counties where not all magistrates have objected. The state courts system considers recusal paperwork part of personnel records.

“A law that allows a state official to opt out of performing some of the duties of the office for sincerely held religious beliefs, while keeping it a secret that the official opted out, is fraught with potential for harm that could be of constitutional magnitude,” he wrote.

Cogburn, an appointee of President Barack Obama, was the first judge to formally strike down North Carolina’s gay marriage ban in October 2014. The McDowell County couple were among plaintiffs in one of the lawsuits that successfully challenged that ban.

Says no evidence of anyone being harmed