The eminent Muslim scholar and renowned Da`iyah, Sheikh `Abdel Khaliq Hasan Ash-Shareef, states: “Almighty Allah has exempted us from such thoughts. What is important is not to talk or to put them into action. The Prophet (peace and blessings be upon him) said, “Allah has forgiven my followers the evil thoughts that occur to their minds, as long as such thoughts are not put into action or uttered.” However, there is more fear if one dwells on such imaginations that he may talk of them or fall into sin and put them into action. So, when such thoughts come to one’s mind, one has to ask Allah for refuge against Satanic whispers. Instead, one has to satisfy his desire in a lawful means by fantasizing having sex with his wife or having intimate relations with her.
If you cannot control such thoughts and you find it a problem, they are encouraged to consult a psychiatrist to help overcome such fantasies or imaginations.