Online Motion Planning for Safe Human-Robot Cooperation using B-Splines and Hidden Markov Models