Update globalvars.h

Moved indexing template from decode/encode to create an efficient global method of indexing/replacing elements of an array