This can be controlled but can not be completely obsoleted ! To control tracks will be required to be circumferenced by barbed wires , demolition of unauthorised dwellings , tress passers will required to controlled at critical incident points (identification would be required) .
Ultimate solution would be to seclude rail tracks in the dense areas from surrounding activities ! Which will be more costly than repairing windows in such case !!