Slang reference to the male testes. Associated to a male's testicles, mainly due to the orb like shape of the testicles, hence the popular phrases.
Also can be used to reference money, to show the 'marbles' or to indicate they are 'throwing in all the marbles' which refers to putting all their money in.
Further reference (marbles) of one's mental capacity, in 'they don't have all their marbles'.
Sort of referring to the brain cells.