The first clause is just some fluff setting out one reason why the right to bear arms shall not be infringed, but it in no way modifies the second clause. Think of it this way. Rewrite the sentence as, "Thomas Jefferson has a nice dog, the right of the people to keep and bear arms shall not be infringed."
The first clause in no way modifies the meaning of the second clause.
"A well educated citizenry being neccesary to the survival of a free nation, the right of the people to keep and read books shall not be infringed."
Use this example on liberal gun grabbers, and ask them how this can be used to mean that only properly qualified universities and schools and other goverment authorized educators should be allowed the "collective right" to own or read books.