Issuing three talaaqs in the absence of one's wife

Q: I constantly have waswasa regarding different things, such as fears of losing important things and intrusive thoughts about divorce. 

Recently, while driving alone, I had thoughts of talaq, and I became worried about accidentally uttering the word and losing my wife. To counter these thoughts, I ended up saying the statement three times "main tumhy talaq deta hon" with my wife's name, thinking it would stop my mind from repeating it in front of her. 

However, I later read that divorce in isolation might still be valid. I also consulted an Imam at the Masjid, who assured me that the talaq is not valid. I would appreciate your opinion on this matter.