What should I do in such a situation?
You are suffering from waswas and it's okay, you will have to find a treatment for it (let it be ruqyah, therapy or whatever suits you).
Am I out of the religion because of these thoughts?
No. Actually some Ulama believe such fears are good signs of being faithful, some people told the Prophet once that they are suffering in their minds from extremly grave things, the Prophet told them their fear is "the pure faith" (sahih).
It is narrated on the authority of Abu Huraira that some people from
amongst the Companions of the Apostle (ﷺ) came to him and said:
Verily we [find] in our minds that which every one of us considers
it too grave to express. He (the Holy Prophet) said: Do you really
find such things? They said: Yes. Upon this he remarked: That is the pure faith.
Imam Al-Nawawi commented on that hadith saying:
It means: Your horror in saying it is pure faith. If this is
grave, and there is intense fear of it, and of uttering it, in
let alone believing in it, it is only for the one who has completely and
truly achieved faith, and is free of suspicion and doubts.