I think that underwear is often white because it preserves the appearance of the garment which you wear on top of it. It does not take away colour, but in fact it may bring out the patterns, designs and colours of the outer garment. For example, if one was wearing a yellow dress with black underwear then the dress may appear an ugly dull mustard colour. However, if one was wearing a yellow dress with white underwear then the colour of the dress may be brought out and the yellow may appear brighter.
Another reason why may be because white is a colour often associated with cleanliness, and wearing the colour white may give one the feeling of being clean. However white is a colour which also gets dirty easily, therefore it is easy to spot dirt so one may know when he/she is dirty.