It's associated with the body attempting to get warmer. Your body goes into a survival mode when experiencing cold conditions. The vibrations throughout your body including the chattering of the teeth creates heat. At least it's what I remember from a class in my past.
I agree, along with shivering, it's the body's way of trying to keep warm. The time you really have to start to worry is when your body stops shivering. If it's still cold then it means that you're going into a more severe state of hypothermia.