Am I too old for academia after a PhD? Currently, I am applying for PhD positions at United States and Canadian Universities. I will be 35 when I start my PhD in Computer Science/Machine Learning, and probably I will finish it around the age of 40.

Will I be banished from academic positions considering a possible PostDoc time and what about industry positions ? Should I plan my study towards industry or academia from the research perspective ?
No.

Age discrimination is illegal in the US and (I assume) Canada.  If you're worried, just don't put your date of birth on your CV.  Most people don't.

Hiring committees just don't care how old you are.  All that matters is the quality and impact of your research.