ALWAYS post ALL your code, so that you can avoid so much back and forth.
You are taking the correct approach to estimate the average drift rate, and subtract that from the current gyro angular rate reading. There are three drift rates, one for each axis.
offsetVal should be declared to be the same type as the individual gyro reading, but you cannot add 1000 16 bit integer values without using intermediate variables declared as long (32 bit) integers.
In other words, this is wrong:
int totalVal = 0;