Sounds like there is a problem with the shift interlock system. From a malfunctioning interlock solenoid, the brake light switch, or an electrical problem.
Any work that was done recently on the car? This problem just started suddenly or was happening for some time?
2002 Corolla S, Silverstream, 1.8L 1ZZ-FE (VVT-i)
2003 Matrix XRS, Cosmic Blue, 1.8L 2ZZ-GE (VVTL-i) - RIP
2009 Matrix XRS, Blue Streak, 2.4L 2AZ-FE (VVT-i)