A detailed evaluation of the thoughts is required. Your problem could be indicative of a condition called Obsessive compulsive disorder. A problem where the thoughts occur in one's mind against his or her will, and is often very distressful. With suitable medications it can be completely resolved. You need to consult with a psychiatrist for it.
Next Steps
Kindly consult with a psychiatrist. For more information regarding this problem you can ask a detailed query here on practo.