As-Salaam alaikum,
The Noble Messenger of Allah, Sallallahu alaihi Wasallam, said:--

"Allah has written for the son of Adam his inevitable share of adultery whether
he is aware of it or not: The adultery of the eye is the looking (at something which
is sinful to look at), and the adultery of the tongue is to utter (what is unlawful to utter),
and the inner self wishes and longs for (adultery) and the private parts turn that into
reality or refrain from submitting to the temptation."
[Sahih Bukhari].

Immodesty, obscenity and any form of adultery be it of the eyes, ears, tongue or thoughts make a hole in the heart. Through this hole leaks out Imaan (faith). So, no matter how much you try to fill your heart with Imaan, it will constantly flow out because of this hole. While an inappropriate thought may occur to anybody, as Shaytan is always trying to inspire people with these, yet it is the person who decides whether to entertain such ideas, discussion, temptation or turn away from them.

If you are on a plateau, the more centrally you stand the safer you are. The closer you get to the sides, the greater is the chance... the danger that you might fall off the edge!! Therefore, to avoid the major form of adultery, we should stay away from its minor forms... ie the adultery of the eyes, tongue, ears and thoughts. That way, we will be safer. Avoid movies that glamorize the immoral; avoid hearing obscene talks. If an indecent thought occurs to you, seek refuge with Allah, Subhanahu Wa Ta'ala, from Shaytan and don't entertain such thoughts.