All perfect praise be to Allah, The Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
What you heard is incorrect. Perhaps it is based on the report that reads, "Whoever looks intentionally at the ‘Awrah of his fellow Muslim, Allah will not accept his prayers for forty days."
This report is not authentic; rather, Ash-Shawkaani said about it: "Its chain of narration includes a liar." [Al-Fawaa'id Al-Majmoo‘ah]
Shaykh Al-Albaani classified it as Munkar (denounced/rejected) in his book Silsilat Al-Ahaadeeth Adh-Dha‘eefah.
Allah knows best.