Motor shield direction

I am trying to control my model train with Arduino.
Some electric components in the train include 12V DC motor and 2 direction LED. (the diagram is shown below)
So, I use motor shield (L298) (same as official version) with Arduino Uno.
When I connect to the train, the motor is working perfectly.
Only problem is the direction light.
Both LEDs are light up. Also, same thing happened on the motor shield indicator.
If I disconnect the train, the indicator goes normal.
I guess it is caused by back EMF of the motor.
So, my question is how to make the direction light of train working.
Do I need to add some components between the shield and the train if I don’t want to modify the train? Or maybe just add some statements in the code.

This is my first post and I don’t; speak English.
So, sorry for my poor English.