This paper describes a novel method for the estimation of the trajectory curve and orientation of a rigid body moving along a railway track. Compared to other recent developments in the literature, the presented approach has the significant advantage of tracking the position and orientation of a railway vehicle using inertial sensors only (a 3D gyroscope and a 3D accelerometer), excluding global position sensors (GNSS or total station) and also excluding global orientation sensors (magnetometers or inclinometers).The algorithm is based on a kinematic model of the relative motion of the body with respect to the track. This kinematic model is used as the system equations of a Kalman filter algorithm that includes in the state vector the coordinates used to define the position and orientation of the body. Two different Kalman filter approaches are described. In the first one, the position and orientation are calculated independently. In the second one, both position and orientation are calculated as a coupled problem. Crucial to the success of the results of the Kalman filters is the use of the correct covariance matrices associated with the system process and the measurements. Again, two approaches are used for the estimation of the covariance matrices. One is based on the use of experimental results with a known output. The other one is based on constrained maximum likelihood estimation. The calculated trajectory and orientation are applied in this research to the problem of track geometry measurement. This is a very demanding application because the measurement of track irregularities requires millimetric accuracy. A scale track with known design geometry and irregularities is used to conduct experiments for tuning and evaluating the quality of the output of the algorithm. Results show that the developed algorithm is accurate enough for this application. They also show that, using either of the two proposed Kalman filtering approaches, the constrained maximum likelihood method for the estimation of the covariance matrices performs similarly to the known-output method. This is very convenient because it allows a straightforward application of the observation model in different scenarios.