Last Thursday, three men were hanged in Iran for the crime of lavat, sexual intercourse between two men. The case is considered extreme even by Iranian standards, because while the death penalty is in place for homosexuality, it is usually enforced only when there is a charge of assault or rape alongside it; the accusations in these three cases were of consensual sex.

In Uganda, politicians have been seeking since 2009 to institute a strikingly nasty piece of legislation: the death penalty for "aggravated homosexuality" (being homosexual more than once) and, in a totalitarian touch, penalties for teachers, doctors and even parents who suspected that someone in their care was gay but didn't report them. In Belize, there is a law on the statute books that criminalises homosexuality; a gay rights group in the country, Unibam, has brought a motion challenging the law, and had this reply from the minister of works, Anthony "Boots" Martinez: "My position is that God never placed anything on me for me to look at a man and jump on a man. I'll be clear on it … How would you decriminalise that, I am sorry, but that is law. Not only is the law made by man, that is a law made from the Bible. Why you think God made a man and a woman, man has what woman wants, and woman has what man wants, it's as simple as that. I'll fight tooth and nail to keep that law."

For lesbian and gay people who live in one of the 82 countries where homosexuality is criminalised, the world is not getting better: it is getting significantly, demonstrably worse. The irony – it's actually not an irony, it's a source of great shame, but it is also an unhappy coincidence – is that 40 of these countries are members of the Commonwealth, and this is a British export. Homosexuality was criminalised here in the 1880s, and was therefore part of our legislative package in the age of empire. By the time it was decriminalised in England and Wales in the Sexual Offences Act of 1967 (Scotland followed in 1980 and Northern Ireland in 1982), we no longer had any control over Commonwealth jurisdictions. The repeal came after a report by Lord Wolfenden in 1957; if its findings had only been enacted more swiftly, today unnumbered people across the Commonwealth – at an estimate, more than a million – would be living entirely different lives. Jonathan Cooper, CEO of the Human Dignity Trust, says: "The human misery that criminalisation causes can never be overestimated. The impact on lesbian and gay people growing up, you cannot overestimate what it does to people living under those laws, even if they're not being prosecuted. Just the fact that the rest of society is denied to them, they have no access to it."

That's the bad news. Incredibly, for a story like this, there is also good news. Apart from specific campaigning bodies such as Stonewall and more general human rights agencies such as Amnesty, there is a new crop of organisations trying to tackle this in a different way. This isn't another story about new media taking on old battles, though an awe-inspiring Facebook campaign, We Are Everywhere, has gained ground since the hangings last week. But two groups in particular are taking the old-fashioned routes of top-level pressure and the rule of law. Kaleidoscope is described by its director, Lance Price, thus: "First, we're being driven by the experience of the people in the countries we're talking about. If you look at any country in the world where there has been progress, it started with a small group of people who had the courage to stand up. It's their struggle, these are their countries. Second, the people involved have been active in politics at a very high level [Price is a former adviser to Tony Blair], or active in the civil service at a very high level. I'm not bragging. But we're working all the time on behalf of people who struggle to have a voice, and we can bring them to the attention of powerful people who do make decisions, in their own countries and here."

It's not lobbying, exactly; it's not diplomacy, but it is characterised by "quiet conversations with people who can make a difference. We're going to have to engage with people, quietly, rather than shouting at them."

The other group, the Human Dignity Trust, is not a campaigning organisation either. It is not there to raise awareness and is not even there to put pressure on governments. It is setting out to change the law, in the Commonwealth and beyond, on the basis that it is a breach of international human rights to criminalise someone's sexual identity.

With a few exceptions – Saudi Arabia being one – all the countries that criminalise homosexuality are signed up to either the International Covenant on Civil and Political Rights or they are bound by test case rulings in their respective courts. "This is a matter of law," Cooper says. "Once you're not following the law, you're undermining the rule of law." This is reflected in the list of the trust's patrons – the former attorney general of India; the former secretary general of the Commonwealth; Lord Woolf, former lord chief justice of England and Wales; and a former judge at the Intra-American court of human rights. "They are not pursuing this as part of a lesbian and gay agenda. It's an international rights law agenda," says Cooper.

The story of the trust is this: when Uganda's homophobic upsurge began two years ago, Tim Otty, a QC with a "strong sense of fairness" (according to his entry in Chambers UK), was asked by the Commonwealth Association to give his advice on the law, and found it, perhaps unsurprisingly, to be in breach of their human rights treaty obligations. Cooper, also a barrister and a friend of Otty, explains how the situation evolved: "Tim is pretty establishment – he's at Blackstone chambers, he's not somebody you would associate with lesbian and gay issues. Unlike me, because I've been around these issues for 20, 30 years; I've done transgender cases, I've done sexuality in the armed forces cases, I've done loads of this type of stuff. So I was not at all surprised when, as we found out in our research, 80-plus jurisdictions continue to criminalise homosexuality around the world. That's almost half the countries in the world." He was amazed that countries still criminalised in flagrant violation of international human rights law, even having signed the treaty.

The test case for European law was Jeff Dudgeon v the United Kingdom in 1981, when the activist brought a case against the British government for the fact that criminalisation was still in force in Northern Ireland. "In a way that was the revolution," says Cooper. "Human rights now protected the lesbian and gay identity. But the Brits didn't over-defend Dudgeon." If you are looking for excessive defence, that happened in the Repulic of Ireland in the late-80s. "They threw everything at this case, to say: you are not going to change our law, human rights law cannot change Ireland's Christian-based law. The Strasbourg court said: 'Actually, we can.'" After one more case, in Cyprus, this became a settled matter for the Council of Europe. Then, following a case brought by Nicholas Toonan in Australia in 1991, the same decision was reached by the UN. "By the mid-90s, it had been settled: international human rights law doesn't protect lesbian and gay rights; it protects identity. And as a consequence of protecting identity it protects you as a gay man or a lesbian woman from having your identity criminalised. That's how it works," Cooper explains.

So all the trust has to do now is change the world, through test case litigation. It does so by finding an individual who is mounting a challenge against, say, the government of Belize, and then, to put it a layman's way, piling in. "I email our legal panel, asking: anyone have any experience of litigating in Belize? Someone comes back and says yeah, we'll represent you in this legal challenge. They bring in as their counsel Lord Goldsmith, and the former attorney general of Belize, Godfrey Smith. We turn up as the international community, with a legitimate interest in the outcome of this case, but we do change the nature of the struggle because we have approached it on the basis that it's a major legal challenge. That is our intention." They're not going to know what's hit them, I observe. "You almost feel sorry for the judge!" Cooper replies, delighted.

Naturally, an appeal will be mounted, whoever loses, and the case will then go to a higher court. "What that means is that when we turn up in the difficult places of Africa and Asia, it's watertight. You can imagine them saying: 'Well, that's South Africa, that's the US supreme court' and trying to distinguish them. But it would be very difficult to distinguish two privy council decisions, one from the South Pacific, one from the Caribbean. If you are that independent judge in Kenya, faced with those authorities, how do you say: 'We're going to retain criminalisation'? You can't."

Price is quite cautious about the work he's taken on: he thinks the process will be slow, and its impact subtle. "If we can just begin to level the playing field a bit so that the other side is put, that will be progress. Because, at the moment, those who want to preach hate have pretty well got a free run."

Cooper, also measured but with the fire of optimism in his eyes, thinks they could have all the decisions they need in five years. "We will have to pay for cases in jurisdictions; I don't see why local lawyers should do it pro bono. We will fundraise, and there is something rather charming that you can say to somebody: 'If you give us £50,000, I can more or less guarantee that you will have decriminalised homosexuality in Tonga.' And actually, you know, that's great."