It could be very frightening to have these thoughts but you have to understand that these thoughts are self perpetuating.
Once a thought comes , you feel anxious (emotions) leads to behaviour like being fidgety...trying to undo the thinking ( eg trying to avoid those thoughts)...then more thought come in and you get more anxious why am I having these kinds of thoughts...and the cycle goes on. And you lose sleep, your concentration
You become fixed to this idea.You have to break this cycle.
Please consult a psychiatrist for detailed evaluation and further management
Next Steps
Please consult A psychiatrist