By Ayanjit Sen
BBC corespondent in Delhi
The high court in the Indian capital Delhi has dismissed a legal petition that sought to legalise homosexuality.
The government says public morals need to be protected
The petition challenged laws which deem homosexual acts to be "unnatural criminal behaviour".
The court ruled that the "validity of a law" cannot be challenged by anyone who is "not affected by it".
The petition, filed by a voluntary organisation, argued that it is wrong for homosexuality to be a punishable offence in 21st century India.
The petition was filed by the HIV and Aids organisation, the Naz Foundation.
It alleged that the police use the law to harass homosexuals.
Lawyers for the government earlier argued in court that homosexuality cannot be legalised in India because society strongly disapproves of it.
"Indian society, by and large, disapproves of homosexuality and justifies it being treated as a criminal offence even when adults indulge in private," said a government lawyer.
The government argued that that the abolition of the law dealing with what they termed as "unnatural sex acts" could result in an increase in delinquent behaviour.
"While the right to respect for private and family life is undisputed, interference by public authority in the interest of public safety and protection of health and morals is equally permissible.
"This is precisely what the law does," said a government affidavit.
Legal experts are debating the court's ruling that petitions against the law cannot be brought by anyone who is "not affected by it".
It is unclear what exactly this phrase means, but some lawyers argue that public interest petitions should be filed by affected people rather than by organisations representing them.