This is a fairly complex question and I do not have the tenacity to look through primary sources at this time.
The short answer is that Siam was able to keep it's independence because it was the land that abutted British India and French Indochina and it was able to diplomatically position itself between the two empires.
If it was taken over by England then it was feared or understood that a conflict could develop with France, and if it was taken over by France then it was understood that a conflict with England could develop.
This was understood by all parties, including the Siamese who simultaneously maintained a good relationship with China, and this allowed China to step in an reap massive trade profits when British India collapsed.
You can check out the Burney Treaty or the Bowring Treaty which effectively made Siam a sort of "protectorate" of England because it opened up trade and made Siam an asset. This reversed about a century? of isolationism in the kingdom and it wasn't long before the French demanded a similar agreement. Siam even signed a trade agreement with the US.
So England had just dominated China during the Opium wars and Siam signs a trade deal with them... at the same time Siam is friendly to the Chinese... this makes them a much greater challenge should the French ever desire to invade and at the same time the British and French were both having much greater problems with their colonial possessions so it just never made sense for them to try and expand and take over Siam. It was more benefit to both empires to conduct trade with them and focus on their own empires as opposed to having to worry about going to war with each other (again).