Fix warnings compiling 64bits

Added typecasts to avoid warnings compiling in 64 bits.
Many of them are down-coversions from size_t to int, not sure if this is right or not.
On the same token, many of the APIs that receive int as params I think are OK with int, BSON objects are rarely going to overflow the limits of int, so this conversions may be OK